package com.ruoyi.tmsdriveracc.utils;

import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.teaopenapi.models.Config;
import org.springframework.stereotype.Component;

/**
 * @ClassName: SmsUtil
 * @Description: 发送短信工具类
 * @Author 小何
 * @Date 2022/4/20 21:14
 * @version: 1.0
 */
@Component
public class SmsUtil {
    /**
     * 使用AK&SK初始化账号Client
     *
     * @param accessKeyId
     * @param accessKeySecret
     * @return Client
     * @throws Exception
     */
    public static com.aliyun.dysmsapi20170525.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
        Config config = new Config()
                // 您的AccessKey ID
                .setAccessKeyId("LTAI5tNAZGN3yhdjp1iPa5ws")
                // 您的AccessKey Secret
                .setAccessKeySecret("RThUrW7AkSHqqOPjEWzVu2PWgZvZKw");
        // 访问的域名
        config.endpoint = "dysmsapi.aliyuncs.com";
        return new com.aliyun.dysmsapi20170525.Client(config);
    }

    public void sendSmsTest(String phone, String param) throws Exception {
        com.aliyun.dysmsapi20170525.Client client = SmsUtil.createClient("accessKeyId", "accessKeySecret");
        SendSmsRequest sendSmsRequest = new SendSmsRequest()
                .setSignName("阿里云短信测试")
                .setTemplateCode("SMS_154950909")
                .setPhoneNumbers(phone)
                .setTemplateParam("{\"code\":\"55555\"}");
        // 复制代码运行请自行打印 API 的返回值
        client.sendSms(sendSmsRequest);
        System.out.println(phone);
    }
}



